package com.oocl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.oocl.dao.BookDao;
import com.oocl.pojo.Books;
import com.oocl.util.DBUtil;

public class BookDaoImpl implements BookDao{

	@Override
	public List<Books> findAll() {
		Connection connection  = null;
		connection = DBUtil.getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "select * from books";
		List<Books> books = new ArrayList<Books>();
		Books book = null;
		try {
			ps = connection.prepareStatement(sql);
			rs = ps.executeQuery();
			while(rs.next()){
				book = new Books();
				book.setId(rs.getString(1));
				book.setName(rs.getString(2));
				book.setImage(rs.getString(3));
				books.add(book);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			DBUtil.release(null, ps, connection);
		}
		return books;
	}

}
